import 'dart:convert';
import 'package:gameplay_flutter/lib_basemodel/chat_room/kh_chat_room_enter_model.dart';
import 'package:gameplay_flutter/m_chatroom/src/interface/room_overlay_mixin.dart';
import 'package:gameplay_flutter/m_chatroom/src/interface/room_route_aware.dart';
import 'package:gameplay_flutter/m_chatroom/src/interface/room_setting_mixin.dart';
import '../../../lib_baseview/root_page.dart';
import '../hall/room_main/room_controller_mixin.dart';
export '../extensions/room_extension.dart';
import '../../../lib_baseview/provider.dart';

///房间全局数据定义start
class RootProxyModel extends JRChangeNotifier
    with
        RoomControllerMixin,
        RoomSettingMixin,
        RoomOverlayMixin /* ,RoomMsgNotifierMixin  */
{
  static RootProxyModel? _instance;
  static RootProxyModel? get instance => _instance;

  late RoomRouteAware _roomRouteAware;

  RootProxyModel._() {
    _roomRouteAware = RoomRouteAware(this);
    appNavigatorObserver.add(_roomRouteAware);
  }

  factory RootProxyModel() {
    _instance ??= RootProxyModel._();
    return _instance!;
  }

  release() async {
    if (!inRoom) return;

    await roomPageModel?.realDispose();
    leaveChannel();
    hideOverlay();
    notifyListeners();
  }

  @override
  void notify() {
    notifyListeners();
  }

  @override
  void dispose() {
    appNavigatorObserver.remove(_roomRouteAware);
    // super.dispose();
  }

  @override
  KHChatRoomEnterModel? get roomEnterModel => roomPageModel?.roomEnterModel;
}
